package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {


    //todo 根据条件查询规格参数集合
    //todo 根据规格参数组的id 查询对应的组内参数
    @Override
    public List<SpecParamDTO> queryParams(Long gid, Long cid, Boolean searching) {

        List<SpecParam> group_id = this.query().eq(gid!=null,"group_id", gid)
                .eq(cid!=null,"category_id",cid)
                .eq(searching!=null,"searching",searching)
                .list()

                ;
        List<SpecParamDTO> specParamDTOS = SpecParamDTO.convertEntityList(group_id);

        return specParamDTOS;
    }

    //todo 新增规格参数
    @Override
    @Transactional
    public void addParam(SpecParamDTO paramDTO) {
         //增加了规格参数  其关联的别的 也要进行更新
        //接口文档中还有 value
        this.save(paramDTO.toEntity(SpecParam.class));
    }

    //todo 修改规格参数
    @Override
    @Transactional
    public void updateParam(SpecParamDTO paramDTO) {
        //规格参数的修改 留待后面优化

        this.updateById(paramDTO.toEntity(SpecParam.class));


    }


}